# [n,m] = map(int, input().split())
# employees = [None for _ in range(n)]
# for i in range(n):
#     employees[i] = list(map(int, input().split()))
# [x,y] = map(int, input().split())
# departments = map(int, input().split())

class Solution:
    def __init__(self) -> None:
        [self.n, self.m] = map(int, input().split())
        self.employees = [None for _ in range(self.n)]
        for i in range(self.n):
            self.employees[i] = list(map(int, input().split()))
        [self.x,self.y] = map(int, input().split())
        self.departments = list(map(int, input().split()))
        self.ans = set()
    
    def check(self, pos):
        x = pos[0]
        y = pos[1]
        index = x*self.n + y
        if 0<=x<self.n and 0<=y<self.m:
            if self.employees[x][y] in self.departments:
                if index not in self.ans:
                    self.ans.add(index)
                    self.invite(pos)
    
    def invite(self, pos):
        x = pos[0]
        y = pos[1]
        self.check([x-1, y])
        self.check([x, y-1])
        self.check([x+1, y])
        self.check([x, y+1])


run = Solution()
run.invite([run.x, run.y])

run.ans.discard(run.x*run.n+run.y)
print(len(run.ans))